package com.neusoft.yuejian12.yuejian_12.fragment;


import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.neusoft.yuejian12.yuejian_12.R;
import com.neusoft.yuejian12.yuejian_12.adapter.ActivityListAdapter;
import com.neusoft.yuejian12.yuejian_12.javabean.ActivityBean;
import com.neusoft.yuejian12.yuejian_12.listener.RetrofitListener;
import com.neusoft.yuejian12.yuejian_12.model.ActivityModel;

import java.util.List;


/**
 * A simple {@link Fragment} subclass.
 */
public class ActivityFragment extends Fragment implements View.OnClickListener,RetrofitListener<List<ActivityBean>> {

    //声明
    private RecyclerView recyclerView;
    private View view = null;
    private ActivityListAdapter activityListAdapter;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {

        view =  inflater.inflate(R.layout.fragment_activity, container, false);
        initViews();
        getActivitylist();
        return view;
    }
    //初始化控件
    private void initViews(){
        recyclerView = (RecyclerView) view.findViewById(R.id.rV_activity);
        recyclerView.setLayoutManager(new LinearLayoutManager(this.getActivity()));
        recyclerView.setItemAnimator(new DefaultItemAnimator());

    }

    private void getActivitylist(){
        ActivityModel activityModel = new ActivityModel();
        activityModel.activitylist(this);
    }

    @Override
    public void onSuccess(List<ActivityBean> activityBeen) {
        activityListAdapter  = new ActivityListAdapter(ActivityFragment.this.getActivity(),activityBeen);
        recyclerView.setAdapter(activityListAdapter);
    }

    @Override
    public void onFail() {

    }

    @Override
    public void onClick(View v) {

    }
}
